package org.hncors.gnssparse.base;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.KeyEvent;


/**
 * Created by TianHongChun on 2016/5/15.
 */
public abstract class BaseExitActivity extends BaseActivity {

    private long exitTime = 0;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }
    //双击后退按钮关闭应用
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if(keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN){
            if((System.currentTimeMillis()-exitTime) > 2000){
                showMsg("再次点击退出应用");
                exitTime = System.currentTimeMillis();
            } else {
                MyApplication.getInstance().exit();
            }
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
}
